package com.ruoyi.backend.controller;

import com.ruoyi.backend.pojo.EcologicalSupervisionReport;
import com.ruoyi.backend.service.EcologicalSupervisionReportService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Api(tags = "生态监管报告管理相关接口", value = "MySQL数据库表主导执行(所有接口已完成测试)")
@RequestMapping("/backend/ecologicalSupervisionReport")
@RestController
public class EcologicalSupervisionReportController {

    @Autowired
    EcologicalSupervisionReportService ecologicalSupervisionReportService;

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "创建生态监管报告接口")
    @PostMapping("/create")
    public R<String> create(@RequestBody EcologicalSupervisionReport ecologicalSupervisionReport) {

        ecologicalSupervisionReportService.create(ecologicalSupervisionReport);
        return R.ok("生态监管报告创建成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "删除生态监管报告接口")
    @DeleteMapping("/delete")
    public R<String> delete(@RequestParam("supervise_id") @NotNull(message = "生态监管报告ID不能为空") Integer superviseId) {

        ecologicalSupervisionReportService.delete(superviseId);
        return R.ok("生态监管报告删除成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "更新生态监管报告接口")
    @PutMapping("/update")
    public R<String> update(@RequestBody @Validated(EcologicalSupervisionReport.Update.class) EcologicalSupervisionReport ecologicalSupervisionReport) {

        ecologicalSupervisionReportService.update(ecologicalSupervisionReport);
        return R.ok("生态监管报告更新成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "查询生态监管报告接口")
    @GetMapping("/search")
    public R<List<EcologicalSupervisionReport>> search(@RequestParam(name = "mineId", required = false) String mineId,
                         @RequestParam(name = "superviseType", required = false) String superviseType,
                         @RequestParam(name = "superviseTimeStart", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate superviseTimeStart,
                         @RequestParam(name = "superviseTimeEnd", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate superviseTimeEnd
                         ) {

        List<EcologicalSupervisionReport> ecologicalSupervisionReportList = ecologicalSupervisionReportService.search(mineId, superviseType, superviseTimeStart, superviseTimeEnd);
        return R.ok(ecologicalSupervisionReportList,"生态监管报告查询成功");
    }

    @DataSource(DataSourceType.MASTER)
    @ApiOperation(value = "查询所有生态监管报告接口")
    @GetMapping("/all")
    public R<List<EcologicalSupervisionReport>> all() {

        List<EcologicalSupervisionReport> ecologicalSupervisionReportList = ecologicalSupervisionReportService.serachAll();
        return R.ok(ecologicalSupervisionReportList,"生态监管报告查询成功");
    }
}
